package com.ps.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ps.service.IUserService;
import com.ps.vo.PageUtil;
import com.ps.vo.User;

@Controller
public class UserController {

	@Autowired
	IUserService userService;
	
	@RequestMapping("/queryUserList")
	@ResponseBody
	public PageUtil<User> queryUserList(@RequestParam int pageSize,@RequestParam int currentPage){
		PageUtil<User> pageUtil=new PageUtil<>();
		pageUtil.setCurrentPage(currentPage);
		pageUtil.setPageSize(pageSize);
		pageUtil=userService.queryUserList(pageUtil);
		pageUtil.getRows().forEach(System.out::println);
		return pageUtil;
	}
	
	@GetMapping("/deleteUserById")
	public void deleteUserById(@RequestParam int id) {
		System.out.println("deleteUserById进来了..."+id);
		userService.deleteUserById(id);
	}
	
	@PostMapping("/updateUser")
	@ResponseBody
	public void updateUser(User user) {
		System.out.println("updateUser :"+user);
		userService.updateUser(user);
	}
	
	@PostMapping("/addUser")
	@ResponseBody
	public void addUser(User user) {
		System.out.println("addUser :"+user);
		userService.addUser(user);
	}
	
}
